//Creado por Eduardo Morales el 21 de noviembre de 2006 
import java.sql.*;

public class SQLHandler{
   
   static String login = "root";
   static String password = "musso";
   static String url = "jdbc:mysql://localhost/biblioteca";
   Connection conn;
   Statement stmt;
	public SQLHandler(){}
	
	public ResultSet select(String consulta) throws Exception{
      conn = null;
      ResultSet res=null;
 
      try
      {
         Class.forName("com.mysql.jdbc.Driver").newInstance();
         conn = DriverManager.getConnection(url,login,password);


         if (conn != null)
         {
            stmt = conn.createStatement();
            res  = stmt.executeQuery(consulta);
      
                 

         }
       }
       catch(SQLException ex)
       {
          System.out.println(ex.getMessage());
       }
       catch(ClassNotFoundException ex)
       {
          System.out.println(ex.getMessage());
       }
		return res;
	}
	
	public boolean insertUpdate(String consulta)throws Exception
   {
      conn = null;
      try
      {
         Class.forName("com.mysql.jdbc.Driver").newInstance();
         conn = DriverManager.getConnection(url,login,password);


         if (conn != null)
         {
            stmt = conn.createStatement();
            stmt.executeUpdate(consulta);
            System.out.println(consulta);
            
         }
       }
       catch(SQLException ex)
       {
          System.out.println(ex.getMessage());
          return false;
       }
       catch(ClassNotFoundException ex)
       {
          System.out.println(ex.getMessage());
       }
       return true;
   }
	
	
	
}